﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Snake : MonoBehaviour
{
    private KeyCode _arrow = KeyCode.W;
    public KeyCode arrow {set => _arrow = value; get => _arrow;}
    private List<MyPoint> _snakePoint = new List<MyPoint> {
        // new MyPoint(Random.Range(0, PublicData.kSreenSize), Random.Range(0, PublicData.kSreenSize)),
        new MyPoint((int)(PublicData.kSreenSize * 0.5), (int)(PublicData.kSreenSize * 0.5)),
    };
    public List<MyPoint> snakePoint {
        set {
            _snakePoint = value;
            // KeyCode.le
        }
        get {
            return _snakePoint;
        }
    }
    // 返回4个反向的向量
    private MyPoint getArrow() {
        
        switch (arrow) {
            case KeyCode.W: 
                return new MyPoint(0, 1);
            case KeyCode.S: 
                return new MyPoint(0, -1); 
            case KeyCode.A: 
                return new MyPoint(0, -1);
            case KeyCode.D: 
                return new MyPoint(0, 1);
            default:
            return new MyPoint(0, 0);
        }
    }

    // 移动蛇
    public void move() {
        
        MyPoint pointTemp = snakePoint[snakePoint.Count - 1];
        MyPoint point = new MyPoint(pointTemp.x + getArrow().x, pointTemp.y + getArrow().y);//point + getArrow(KeyCode.W);
        snakePoint.Add(point);
        snakePoint.RemoveAt(0);
    }
    // 吃食物
}
